<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// 检查登录状态
			this.checkLoginStatus()
			this.loadMessage()
			// #ifdef APP-PLUS
			plus.push.addEventListener('click', function(msg){
				uni.navigateTo({
					url: "/pages/pf/message"
				})
			})
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 检查登录状态
			loadMessage() {
				let user = uni.getStorageSync("user")
				if (!(user === "" || user === null)) {
					uni.request({
						url: "/api/bf/user/message/nopage",
						data: {
							user: user
						},
						method: 'POST',
						success(res) {
							let infoPageInfo = res.data.infoPageInfo.filter(i => i.status === 0)
							let content = "您有" + infoPageInfo.length + "条投资信息未查看，请点击查看~"
							let options = {
								"cover": false,
								"when": new Date(),
								"title": "通知消息"
							}
							let body = {
								"id": "id",
								"key": "key"
							}
							let payload = JSON.stringify(body)
							plus.push.createMessage(content, payload, options)
						}
					})
				}
			},
			checkLoginStatus() {
				// // 从本地存储获取token
				// const token = uni.getStorageSync('token')
				// // 获取当前页面路径
				// const pages = getCurrentPages()
				// const currentPage = pages[pages.length - 1]
				// const currentPath = currentPage ? currentPage.route : ''

				// // 如果未登录且不在登录页面，则跳转到登录页
				// if (!token && currentPath !== 'pages/login/login') {
				// 	uni.reLaunch({
				// 		url: '/pages/login/login'
				// 	})
				// }
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "uview-ui/index.scss";
</style>